package com.wash.shoes.controller.pc;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.ShoeRackPo;
import com.wash.shoes.entity.ShopShoeRackPo;
import com.wash.shoes.exception.WashException;
import com.wash.shoes.service.ShopShoeRackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ljg
 * @since 2024-10-13
 */
@Api(tags = {"PC-门店的鞋架"})
@RestController
@RequestMapping({"/shopShoeRack", "/dev-api/shopShoeRack"})
public class ShopShoeRackController {

    @Autowired
    ShopShoeRackService shopRackService;

    @ApiOperation("没有关联的鞋架")
    @GetMapping("/noConnectionRackList")
    public R<Page<ShoeRackPo>> noConnectionRackList(String rackCode, String shopId) {
        Page<ShoeRackPo> page = shopRackService.noConnectionRackList(rackCode, shopId);
        return R.ok(page);
    }

    @ApiOperation("门店的鞋架")
    @GetMapping("/shopRackList")
    public R<Page<ShoeRackPo>> shopRackList(String shopId) {
        Page<ShoeRackPo> page = shopRackService.shopRackList(shopId);
        return R.ok(page);
    }

    @ApiOperation("门店添加鞋架")
    @GetMapping("/shopAssociateRack")
    public R<String> shopAssociateRack(String rackId, String shopId) {

        ShopShoeRackPo shopRackPo = shopRackService.shopAssociateRack(rackId, shopId);
        if (shopRackPo != null) {
            throw new WashException("该鞋架已经关联门店");
        }
        shopRackPo = new ShopShoeRackPo();
        shopRackPo.setRackId(rackId);
        shopRackPo.setShopId(shopId);
        shopRackService.save(shopRackPo);

        return R.ok(shopRackPo.getId());
    }

    @ApiOperation("门店取消鞋架")
    @GetMapping("/userCancelAssociateShop")
    public R<String> userCancelAssociateShop(String rackId, String shopId) {

        ShopShoeRackPo shopRackPo = shopRackService.shopAssociateRack(rackId, shopId);
        if (shopRackPo != null) {
            shopRackService.removeById(shopRackPo);
        }
        return R.ok(shopRackPo.getId());
    }


}

